package com.tangdi.common;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConnect {//饿汉式
	private static final DBConnect dbconnect = new DBConnect();
	private Connection con=null;
	private DBConnect(){};
	public static DBConnect getInstance() {
        return dbconnect;
        //return ConnectHolder.instance;
    }

	//静态内部类
/*	private static class ConnectHolder{
		private static final DBConnect instance = new DBConnect();
	}*/
    public Connection getConnection(){
    	try {
    		//oracle
/* 			Class.forName("oracle.jdbc.driver.OracleDriver");
    	  	String url="jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
    	  	String name="system";
    	  	String pwd="yang";*/
    	  	
    		//mysql
    	  	Class.forName("com.mysql.jdbc.Driver");
    	  	String url="jdbc:mysql://localhost:3306/gzdfdb?useUnicode=true&characterEncoding=utf-8";
    	  	String name="root";
    	  	String pwd="123456";
    	  	
    	  	
    	    con=DriverManager.getConnection(url,name,pwd);
    	    con.setAutoCommit(false);
	    	return con;
	    }
	    catch (Exception ex) {
	    	ex.printStackTrace();
	    	return null;
	    }
    }
    
}
